package pe.com.rix.taglib.view;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class Button extends BodyTagSupport{
	
	private static final long serialVersionUID = 1L;
	private String customClass;
	private String color;
	private String href;
	private String onClick;
	private String align;
	
	@Override
	public int doAfterBody() throws JspException {
		
		BodyContent bodycontent = getBodyContent();
        String body = bodycontent.getString();
		
		StringBuffer html = new StringBuffer();
		
		String Color = getColor();
		String CustomClass = getCustomClass();
		String OnClick = getOnClick();
		String Align = getAlign();
		String Href = getHref();
		
		if(Color==null) Color = ""; 
		if(CustomClass==null) CustomClass = "";
		if(OnClick==null) OnClick = ""; else OnClick = " onclick='javascript:" + OnClick + "' "; 
		if(Align==null) Align = "btn"; 
		else {
			if(Align.equalsIgnoreCase("center")){
				Align = "btnC";
			}else if(Align.equalsIgnoreCase("center2")){
				Align = "btnC2";
			}else if(Align.equalsIgnoreCase("right")){
				Align = "btnR";
			}else if(Align.equalsIgnoreCase("left")){
				Align = "btn";
			}
			
		}
		if(Href==null) Href = ""; else Href = " href='" + Href + "' ";
		
		html.append("<a class='" + Align + " " + Color + " " + CustomClass + "' " + Href + OnClick + " >");
		html.append("<i></i><span><span></span><i></i>");
		html.append(body);
		html.append("</span></a>");
		
		JspWriter out = bodycontent.getEnclosingWriter();
		try {
			out.print(html.toString());
		} catch (java.io.IOException ex) {
			throw new JspException(ex.getMessage());
		}
		return SKIP_BODY;
		
	}

	public String getCustomClass() {
		return customClass;
	}

	public void setCustomClass(String customClass) {
		this.customClass = customClass;
	}


	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public String getOnClick() {
		return onClick;
	}

	public void setOnClick(String onClick) {
		this.onClick = onClick;
	}

	public String getAlign() {
		return align;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	


}
